package com.yidu.servlet.fileuploaddemo;

import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageEncoder;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;

@WebServlet(name = "helloServlet", value = "/hello-servlet")
public class HelloServlet extends HttpServlet {
    private String message;

    public void init() {
        message = "Hello World!";
    }

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.setContentType("image/jpeg");
        JPEGImageEncoder codec = JPEGCodec.createJPEGEncoder(response.getOutputStream());
        BufferedImage image=new BufferedImage(300,300,BufferedImage.TYPE_INT_RGB);
        Graphics g = image.getGraphics();
        g.setColor(Color.white);
        g.setFont(new Font("隶书",Font.BOLD,30));
        g.drawString("你好",30,30);
        codec.encode(image);
    }

    public void destroy() {
    }
}